//Accepted
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

char a[100], z;
int sum, i, j, k, l, x;

int main (){
	//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);
	scanf("%s", a);
	sum=0;
	z=0;
	for(i=0, j=10;i<10;++i,--j){
		if(('0'<=a[i])&&(a[i]<='9')){
			sum+=(a[i]-'0')*j;
		}
		else if(a[i]=='?'){
			k=j;
			if(i==9)z=1;
		}
		else if(a[i]=='X'){
			sum+=10;
		}
	}
	x=11;
	if(z){
		for(i=0;i<11;++i){
			if((sum+k*i)%11 == 0){
				x=i;
				break;
			}
		}
	}
	else{
		for(i=0;i<10;++i){
			if((sum+k*i)%11 == 0){
				x=i;
				break;
			}
		}
	}
	
	if(x==11)printf("-1");
	else if(x==10)printf("X");
	else printf("%d", x);
	return 0;
}
